package com.future.north.controller;

import com.alibaba.fastjson.JSONObject;
import com.future.north.api.UserService;
import com.future.north.aspect.trace.TraceLog;
import com.future.north.config.MoneyConfig;
import com.future.north.api.model.User;
import com.future.north.utils.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/hello")
@TraceLog(key = "helloController")
public class HelloController {
    @Autowired
    private UserService userService;
    @Autowired
    private MoneyConfig moneyConfig;

    @RequestMapping("/say/{id}")
    public String getSayHello(@PathVariable("id") Long id) {
        ServiceResult<User> ret = userService.getUserById(id);
        if (ret.getSuccess()) {
            return JSONObject.toJSONString(ret.getBody());
        }

        return "say you again";
    }

    @RequestMapping("/money/config")
    public String getMoneyConfig() {
        return moneyConfig.getDescribe();
    }

    @RequestMapping("/page")
    public String getIndex() {
        return "hello";
    }

    @RequestMapping("/list")
    public ModelAndView getList() {
        ModelAndView modelAndView = new ModelAndView("hello/index");

        modelAndView.addObject("user", "高天杰");
        return modelAndView;
    }
}
